package com.wl.center.state.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wl.center.model.state.UpdateContent;
import com.wl.center.model.task.Customer;
import com.wl.center.model.task.User;
import com.wl.center.state.mapper.UpdateContentMapper;
import com.wl.center.state.service.CustomerService;
import com.wl.center.state.service.UpdateContentService;
import com.wl.center.vo.state.UpdateRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
* @author WangLiang
* @description 针对表【update_content】的数据库操作Service实现
* @createDate 2023-02-28 22:15:30
*/
@Service
public class UpdateContentServiceImpl extends ServiceImpl<UpdateContentMapper, UpdateContent>
    implements UpdateContentService {
    @Autowired
    UpdateContentService updateContentService;
    @Autowired
    CustomerService customerService;
    @Override
    public IPage<UpdateRecord> getUpdateContentPage(Page<UpdateContent> page, QueryWrapper<UpdateContent> wrapper) {
        List<UpdateRecord> updateRecordList = new ArrayList<>();//引入中间类updateRecordList
        UpdateRecord updateRecord = new UpdateRecord();//创建一个中间类对象updateRecord
        //调用方法实现分页查询
        Page<UpdateContent> pageUpdate = updateContentService.page(page, wrapper);
        List<UpdateContent> UpdateList = pageUpdate.getRecords();
        IPage<UpdateRecord> page1 = new Page<>();
        for (UpdateContent updateContent:UpdateList) {
            String content = updateContent.getContent();
            Date updateTime = updateContent.getUpdateTime();
            Integer updatePersonId = updateContent.getUpdatePerson();
            User user = customerService.getById(updatePersonId);
            String updatePersonName = user.getName();
            updateRecord = new UpdateRecord();//指定不同的updateRecord对象
            updateRecord.setSetUpdatePersonName(updatePersonName);
            updateRecord.setContent(content);
            updateRecord.setUpdateTime(updateTime);
            updateRecordList.add(updateRecord);
        }
        long pages = pageUpdate.getPages();
        long current = pageUpdate.getCurrent();
        long size = pageUpdate.getSize();
        long total = pageUpdate.getTotal();
        page1.setPages(pages);
        page1.setCurrent(current);
        page1.setSize(size);
        page1.setTotal(total);
        page1.setRecords(updateRecordList);
        return page1;
    }
}




